const http = require('http');
const fs = require('fs');
const path = require('path');
http.createServer(function (request, response) {

    let url = request.url;
    // 如果用户访问什么也没输入, 我们把url重新赋值. /index.html
    url = url == '/' ? '/index.html' : url;

    if (url == '/index.html' || url == '/index.css' || url == '/index.js') {
        // 读数据, 发送数据
        fs.readFile(path.join(__dirname, 'clock', url), 'utf8', (err, data) => {
            if (err) return console.log('文件读取失败');
            response.end(data)
        })
    } else {
        //发送找不到这个页面404
        response.end('404 Not Found')
    }

}).listen(8081);

console.log('Server running at http://127.0.0.1:8081/');